package com.cjh.controller;

import com.cjh.entity.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@RequestMapping("/consumer")
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    private static String restUrl="http://localhost:8010";

    @GetMapping("/list")
    public List<Person> list(){

        return restTemplate.getForObject(restUrl+"/person/list",List.class);
    }

    @GetMapping("/get/{id}")
    public Person get(@PathVariable("id") String id){

        return restTemplate.getForEntity(restUrl+"/person/get/{id}",Person.class,id).getBody();
    }
}
